package com.flx.at.spring.code.test.testbeanlifecycle.processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @Author Fenglixiong
 * @Create 2021/11/2 19:48
 * @Description 所有的Bean都会经过这个方法
 * 应用场景：用来修改Bean的属性
 **/
@Component
public class LifeCycleBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.equals("lifeCycleA")) {
            System.out.println("LifeCycleA postProcessBeforeInitialization...");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.equals("lifeCycleA")) {
            System.out.println("LifeCycleA postProcessAfterInitialization...");
        }
        return bean;
    }
}
